home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / Core / NamSpac.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  11.2 KB  |  393 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        NamSpac.cpp
  3.  
  4.     Contains:    Implementation of ODNameSpace class
  5.  
  6.     Owned by:    David McCusker
  7.  
  8.     Copyright:    © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.         <19>     10/8/95    TJ        Fixes Recomended by Refball
  13.         <18>     9/11/95    CG        #1282719 FB2: Core error code mods.
  14.         <17>      8/3/95    RR        #1257260: Collapse B classes. Remove
  15.                                     somInit methods. Don't call IsInitialized
  16.                                     or SubclassResponsibility
  17.         <16>     7/27/95    DM        #1270320: Mem leaks: GetName() needed to
  18.                                     allocate the name returned
  19.         <15>     7/24/95    CG        #1270320: Memory leak fixes.
  20.         <14>     5/25/95    jpa        Return of <12>: Added SetSynchedToEditors
  21.                                     and IsSynchedToEditors.  [1240150]
  22.         <13>     5/17/95    TJ        Backed out changes from previous checkin.
  23.         <11>     5/11/95    DM        #1181622: Updated file ownership.
  24.         <10>      5/2/95    DM        1242453: InitNameSpace handles errors
  25.          <9>      5/1/95    CG        #1241627    BB: SOM_TRY blocks needed in Core
  26.                                     SOM methods
  27.          <8>     4/26/95    CG        1211082 BB: 5$ Bugs need to be evaluated
  28.                                     and removed from Core
  29.          <7>     3/24/95    CG        #1217023 API: Write and Read use
  30.                                     ODByteArray params instead of Platformfile.
  31.          <6>     1/23/95    CG        #1195019: Added private getter for
  32.                                     fNameSpaceManager.
  33.          <5>     9/29/94    RA        1189812: Mods for 68K build.
  34.          <4>     8/24/94    CG        #1181622: Updated file ownership.
  35.          <3>     8/17/94    CG        #1181493: Exists no longer depends on what
  36.                                     kind of name space it is.
  37.          <2>      8/5/94    VL        Implemented Exists.
  38.          <1>     7/29/94    CG        first checked in
  39.          <1>     6/24/94    CG        first checked in
  40.     To Do:
  41.     In Progress:
  42. */
  43.  
  44. /*
  45.  *  This file was generated by the SOM Compiler.
  46.  *  Generated using: 
  47.  *      SOM Emitter emitxtm.dll: somc/smmain.c
  48.  */
  49.  
  50. #define ODNameSpace_Class_Source
  51. #define VARIABLE_MACROS
  52. #include <NamSpac.xih>
  53.  
  54. #ifndef _ISOSTR_
  55. #include "ISOStr.h"
  56. #endif
  57.  
  58. #ifndef _EXCEPT_
  59. #include "Except.h"
  60. #endif
  61.  
  62. #ifndef _ODMEMORY_
  63. #include "ODMemory.h"
  64. #endif
  65.  
  66. #ifndef _STRHSHTB_
  67. #include "StrHshTb.h"
  68. #endif
  69.  
  70. #ifndef _ODUTILS_
  71. #include <ODUtils.h>
  72. #endif
  73.  
  74. #ifndef _ODDEBUG_
  75. #include "ODDebug.h"    // Adkins -- added
  76. #endif
  77.  
  78.  
  79. SOM_Scope ODISOStr  SOMLINK ODNameSpaceGetName(ODNameSpace *somSelf, Environment *ev)
  80. {
  81.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  82.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceGetName");
  83.     
  84.     SOM_TRY
  85.  
  86.     return ODISOStrFromCStr(_fName); // allocate a copy
  87.     
  88.     SOM_CATCH_ALL
  89.     SOM_ENDTRY
  90.     return kODNULL;
  91. }
  92.  
  93. SOM_Scope ODNSTypeSpec  SOMLINK ODNameSpaceGetType(ODNameSpace *somSelf, Environment *ev)
  94. {
  95.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  96.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceGetType");
  97.  
  98.     return _fType;
  99. }
  100.  
  101. SOM_Scope ODNameSpace*  SOMLINK ODNameSpaceGetParent(ODNameSpace *somSelf, Environment *ev)
  102. {
  103.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  104.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceGetParent");
  105.  
  106.     return _fParent;
  107. }
  108.  
  109. SOM_Scope void  SOMLINK ODNameSpaceSetType(ODNameSpace *somSelf, Environment *ev,
  110.     ODNSTypeSpec type)
  111. {
  112.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  113.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceSetType");
  114.  
  115.     _fType = type;
  116. }
  117.  
  118. //------------------------------------------------------------------------------
  119. // ODNameSpace: Unregister
  120. //------------------------------------------------------------------------------
  121.  
  122. SOM_Scope void  SOMLINK ODNameSpaceUnregister(ODNameSpace *somSelf, Environment *ev,
  123.         ODISOStr key)
  124. {
  125.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  126.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceUnregister");
  127.  
  128.     SOM_TRY
  129.     
  130.     if (_fStringHashTable)
  131.     {
  132.         size_t len = strlen(key);
  133.         _fStringHashTable->Remove((ODUByte*)key, len);
  134.     }
  135.     
  136.     SOM_CATCH_ALL
  137.     SOM_ENDTRY
  138. }
  139.  
  140. //------------------------------------------------------------------------------
  141. // ODNameSpace: Exists
  142. //------------------------------------------------------------------------------
  143.  
  144. SOM_Scope ODBoolean  SOMLINK ODNameSpaceExists(ODNameSpace *somSelf, Environment *ev,
  145.         ODISOStr key)
  146. {
  147.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  148.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceExists");
  149.     ODBoolean    exists = kODFalse;
  150.     
  151.     
  152.     SOM_TRY
  153.  
  154.     if (_fStringHashTable)
  155.     {
  156.         size_t len = strlen(key);
  157.         exists = _fStringHashTable->Exists( (ODUByte*)key, len );
  158.     }
  159.     
  160.     SOM_CATCH_ALL
  161.     SOM_ENDTRY
  162.     
  163.     return exists;
  164. }
  165.  
  166. //------------------------------------------------------------------------------
  167. // ODNameSpace: WriteToFile
  168. //------------------------------------------------------------------------------
  169.  
  170. SOM_Scope void  SOMLINK ODNameSpaceWriteToFile(ODNameSpace *somSelf, Environment *ev,
  171.         ODByteArray* file)
  172. {
  173.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  174.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceWriteToFile");
  175.  
  176. }
  177.  
  178. //------------------------------------------------------------------------------
  179. // ODNameSpace: ReadFromFile
  180. //------------------------------------------------------------------------------
  181.  
  182. SOM_Scope void  SOMLINK ODNameSpaceReadFromFile(ODNameSpace *somSelf, Environment *ev,
  183.         ODByteArray* file)
  184. {
  185.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  186.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceReadFromFile");
  187.  
  188. }
  189.  
  190. //------------------------------------------------------------------------------
  191. // ODNameSpace: WriteToStorage
  192. //------------------------------------------------------------------------------
  193.  
  194. SOM_Scope void  SOMLINK ODNameSpaceWriteToStorage(ODNameSpace *somSelf, Environment *ev,
  195.         ODStorageUnitView* view)
  196. {
  197.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  198.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceWriteToStorage");
  199.  
  200. }
  201.  
  202. //------------------------------------------------------------------------------
  203. // ODNameSpace: ReadFromStorage
  204. //------------------------------------------------------------------------------
  205.  
  206. SOM_Scope void  SOMLINK ODNameSpaceReadFromStorage(ODNameSpace *somSelf, Environment *ev,
  207.         ODStorageUnitView* view)
  208. {
  209.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  210.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceReadFromStorage");
  211.  
  212. }
  213.  
  214. //------------------------------------------------------------------------------
  215. // ODNameSpace: InitNameSpace
  216. //------------------------------------------------------------------------------
  217.  
  218. SOM_Scope void  SOMLINK ODNameSpaceInitNameSpace(ODNameSpace *somSelf, Environment *ev,
  219.         ODNameSpaceManager* mgr,
  220.         ODNameSpace* parent,
  221.         ODULong numExpectedEntries,
  222.         ODISOStr name)
  223. {
  224.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  225.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpaceInitNameSpace");
  226.  
  227.     SOM_TRY
  228.     
  229.     /* Moved from somInit. SOM itself sets fields to zero
  230.     _fName = kODNULL;
  231.     _fType = kODNULL;
  232.     _fNameSpaceManager = kODNULL;
  233.     _fStringHashTable = kODNULL;
  234.     _fParent = kODNULL;
  235.     _fNumInitialEntries = 0;
  236.     _fSynchedToEditors = kODFalse;
  237.     */
  238.     somSelf->InitObject(ev);
  239.  
  240.     _fNameSpaceManager = mgr;
  241.     _fParent = parent;
  242.     _fNumInitialEntries = numExpectedEntries;
  243.  
  244.     if (name)
  245.     {
  246.         ODULong nameLength = ODISOStrLength(name);
  247.         if (nameLength)
  248.         {
  249.             _fName = (ODISOStr)ODNewPtr(nameLength + 1, kDefaultHeapID);
  250.             ODISOStrCopy(_fName, name);
  251.         }
  252.         else
  253.             THROW(kODErrInvalidNSName);
  254.     }
  255.     else
  256.         THROW(kODErrInvalidNSName);
  257.     
  258.     SOM_CATCH_ALL
  259.     SOM_ENDTRY
  260. }
  261.  
  262. //------------------------------------------------------------------------------
  263. // ODNameSpace: GetHashTable
  264. //------------------------------------------------------------------------------
  265.  
  266. SOM_Scope StringHashTable*  SOMLINK ODNameSpaceGetHashTable(ODNameSpace *somSelf, Environment *ev)
  267. {
  268.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  269.     ODNameSpaceMethodDebug("ODNameSpace","GetHashTable");
  270.     
  271.     SOM_TRY
  272.  
  273.     if (!_fStringHashTable)
  274.     {
  275.         _fStringHashTable = new StringHashTable(_fNumInitialEntries);
  276.         _fStringHashTable->Initialize(0);
  277.     }
  278.     
  279.     SOM_CATCH_ALL
  280.     SOM_ENDTRY
  281.     
  282.     return _fStringHashTable;
  283. }
  284.  
  285. //------------------------------------------------------------------------------
  286. // ODNameSpace: GetNumEntries
  287. //------------------------------------------------------------------------------
  288.  
  289. SOM_Scope ODULong  SOMLINK ODNameSpaceGetNumEntries(ODNameSpace *somSelf, Environment *ev)
  290. {
  291.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  292.     ODNameSpaceMethodDebug("ODNameSpace","GetNumEntries");
  293.  
  294.     ODULong    numEntries = 0;
  295.     
  296.     SOM_TRY
  297.  
  298.     if (_fStringHashTable)
  299.         numEntries = _fStringHashTable->GetNumEntries();
  300.         
  301.     SOM_CATCH_ALL
  302.     SOM_ENDTRY
  303.     
  304.     return numEntries;
  305. }
  306.  
  307. //------------------------------------------------------------------------------
  308. // ODNameSpace: GetNameSpaceManager
  309. //------------------------------------------------------------------------------
  310.  
  311. SOM_Scope ODNameSpaceManager*  SOMLINK ODNameSpaceGetNameSpaceManager(ODNameSpace *somSelf, Environment *ev)
  312. {
  313.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  314.     ODNameSpaceMethodDebug("ODNameSpace","GetNameSpaceManager");
  315.  
  316.     return _fNameSpaceManager;
  317. }
  318.  
  319. //------------------------------------------------------------------------------
  320. // ODNameSpace: NotifyDying
  321. //
  322. //    ODNameSpaceManager lets every ODNameSpace know when one of its kind
  323. //    is dying.
  324. //------------------------------------------------------------------------------
  325.  
  326. SOM_Scope void  SOMLINK ODNameSpaceNotifyDying(ODNameSpace *somSelf, Environment *ev,
  327.         ODNameSpace* space)
  328. {
  329.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  330.     ODNameSpaceMethodDebug("ODNameSpace","NotifyDying");
  331.  
  332.     WASSERTM(space != somSelf, "Being notified of self dying");
  333.     if (_fParent == space)
  334.         _fParent = kODNULL;
  335. }
  336.  
  337.  
  338. //------------------------------------------------------------------------------
  339. // ODNameSpace: ~ODNameSpace
  340. //------------------------------------------------------------------------------
  341. SOM_Scope void  SOMLINK ODNameSpacesomUninit(ODNameSpace *somSelf)
  342. {
  343.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  344.     ODNameSpaceMethodDebug("ODNameSpace","ODNameSpacesomUninit");
  345.  
  346.     if (_fStringHashTable)
  347.         ODDeleteObject( _fStringHashTable );
  348.     
  349.     ODDisposePtr( _fName );
  350.     
  351.     ODNameSpace_parent_ODObject_somUninit(somSelf);
  352. }
  353.  
  354. //------------------------------------------------------------------------------
  355. // ODNameSpace: Purge
  356. //------------------------------------------------------------------------------
  357.  
  358. SOM_Scope ODSize  SOMLINK ODNameSpacePurge(ODNameSpace *somSelf, Environment *ev,
  359.         ODSize size)
  360. {
  361.     /* ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf); */
  362.     ODNameSpaceMethodDebug("ODNameSpace","Purge");
  363.  
  364.     ODUnused(size);
  365.     return 0;
  366. }
  367.  
  368. //------------------------------------------------------------------------------
  369. // ODNameSpace: SetSynchedToEditors
  370. //------------------------------------------------------------------------------
  371.  
  372. SOM_Scope void  SOMLINK ODNameSpaceSetSynchedToEditors(ODNameSpace *somSelf, Environment *ev,
  373.         ODBoolean synched)
  374. {
  375.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  376.     ODNameSpaceMethodDebug("ODNameSpace","SetSynchedToEditors");
  377.  
  378.     _fSynchedToEditors = synched;
  379. }
  380.  
  381. //------------------------------------------------------------------------------
  382. // ODNameSpace: IsSynchedToEditors
  383. //------------------------------------------------------------------------------
  384.  
  385. SOM_Scope ODBoolean  SOMLINK ODNameSpaceIsSynchedToEditors(ODNameSpace *somSelf, Environment *ev)
  386. {
  387.     ODNameSpaceData *somThis = ODNameSpaceGetData(somSelf);
  388.     ODNameSpaceMethodDebug("ODNameSpace","IsSynchedToEditors");
  389.  
  390.     return _fSynchedToEditors;
  391. }
  392.  
  393.